s = int(input())
if not 999<s<10000:
    print(0)
else:
    s1=s//1000
    s2=s//100%10
    s3=s%100//10
    s4=s%10
    b1 = s1
    b2 = s1*10+s2
    b3 = s1*100+s2*10+s3
    b4 = s
    b5 = s2*100+s3*10+s4
    b6 = s3*10+s4
    b7 = s2
    b8 = s3
    b9 = s4
    #print(b1,b2,b3,b4,b5,b6,b7,b8,b9) 
    cnt=0
    k=[0] 
    for i in range(2,b1):
        if b1%i==0:
            cnt+=1
    if cnt==0:
        k.append(b1)
    cnt=0
    for i in range(2,b2):
        if b2%i==0:
            cnt+=1
    if cnt==0:
        k.append(b2)   
        
    cnt=0
    for i in range(2,b3//2+1):
        if b3%i==0:
            cnt+=1
    if cnt==0:
        k.append(b3) 
    
    cnt=0
    for i in range(2,b4//+1):
        if b4%i==0:
            cnt+=1
    if cnt==0:
        k.append(b4) 
        
    cnt=0
    for i in range(2,b5//2+1):
        if b5%i==0:
            cnt+=1
    if cnt==0:
        k.append(b5)
    
    cnt=0
    for i in range(2,b6//2+1):
        if b6%i==0:
            cnt+=1
    if cnt==0:
        k.append(b6)
        
    cnt=0
    for i in range(2,b7):
        if b7%i==0:
            cnt+=1
    if cnt==0:
        k.append(b7)
        
    cnt=0
    for i in range(2,b8):
        if b8%i==0:
            cnt+=1
    if cnt==0:
        k.append(b8)
        
    cnt=0
    for i in range(2,b9):
        if b9%i==0:
            cnt+=1
    if cnt==0:
        k.append(b9)
    #print(k)
    f = max(k)
    if f==1 or f==0: 
        print(0)
    else:
        print(f)








    
